<template>
  <el-form
    :model="emailForm"
    status-icon
    :rules="rules"
    ref="emailForm"
    label-width="100px"
    class="demo-dynamic"
  >
    <el-form-item
      prop="password"
      label="密码"
    >
      <el-input
        type="password"
        v-model="emailForm.password"
        placeholder="请输入密码"
      ></el-input>
    </el-form-item>
    <el-form-item
      prop="email"
      label="邮箱"
    >
      <el-input
        v-model="emailForm.email"
        placeholder="请输入邮箱地址"
      ></el-input>
    </el-form-item>
    <el-form-item>
      <el-button
        type="primary"
        @click="submitForm('emailForm')"
      >更改</el-button>
      <el-button @click="resetForm('emailForm')">重置</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  data () {
    return {
      emailForm: {
        password: '',
        email: ''
      },
      rules: {
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ],
        email: [
          { required: true, message: '请输入邮箱地址', trigger: 'blur' },
          { type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change'] }
        ]
      }
    }
  },
  methods: {
    submitForm (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert('submit!')
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm (formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style lang="less" scoped>
</style>
